package com.example.springboot_test.easyexcel.model.builder;

import com.example.springboot_test.easyexcel.enums.BorderSideEnum;
import com.example.springboot_test.easyexcel.model.StyleModel;
import com.example.springboot_test.easyexcel.model.common.BorderModel;
import com.example.springboot_test.easyexcel.model.common.CellShadingModel;
import com.example.springboot_test.easyexcel.model.common.FontModel;
import lombok.Getter;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import java.util.HashMap;
import java.util.Map;

/**
 * 样式信息Builder
 *
 * @author xudongmaster
 */
@Getter
public class StyleModelBuilder {

    /**
     * 样式是否追加
     */
    private final boolean isAppend;
    /**
     * 字体信息
     */
    private FontModel fontModel;
    /**
     * 底纹信息
     */
    private CellShadingModel cellShadingModel;
    /**
     * 边框信息map
     */
    private Map<BorderSideEnum, BorderModel> borderModelMap;
    /**
     * 水平对齐方式
     */
    private HorizontalAlignment horizontalAlignment;
    /**
     * 垂直对齐方式
     */
    private VerticalAlignment verticalAlignment;
    /**
     * 自动换行方式
     */
    private Boolean wrapText;

    /**
     * 旋转角度
     */
    private Short rotation;

    /**
     * 数据格式
     */
    private String dataFormat;

    /**
     * 自动收缩
     */
    private Boolean shrinkToFit;


    protected StyleModelBuilder(boolean isAppend){
        this.isAppend=isAppend;
    }

    public static StyleModelBuilder builder(boolean isAppend) {
        return new StyleModelBuilder(isAppend);
    }

    public StyleModelBuilder fontModel(FontModel fontModel) {
        this.fontModel = fontModel;
        return this;
    }

    public StyleModelBuilder cellShadingModel(CellShadingModel cellShadingModel) {
        this.cellShadingModel = cellShadingModel;
        return this;
    }

    public StyleModelBuilder borderModel(BorderSideEnum borderSide, BorderModel borderModel) {
        if (borderModel == null) {
            return this;
        }
        if (this.borderModelMap == null) {
            this.borderModelMap = new HashMap<>();
        }
        this.borderModelMap.put(borderSide, borderModel);
        return this;
    }

    public StyleModelBuilder horizontalAlignment(HorizontalAlignment horizontalAlignment) {
        this.horizontalAlignment = horizontalAlignment;
        return this;
    }

    public StyleModelBuilder verticalAlignment(VerticalAlignment verticalAlignment) {
        this.verticalAlignment = verticalAlignment;
        return this;
    }

    public StyleModelBuilder wrapText(Boolean wrapText) {
        this.wrapText = wrapText;
        return this;
    }

    public StyleModelBuilder rotation(Short rotation) {
        this.rotation = rotation;
        return this;
    }

    public StyleModelBuilder dataFormat(String dataFormat) {
        this.dataFormat = dataFormat;
        return this;
    }

    public StyleModelBuilder shrinkToFit(Boolean shrinkToFit) {
        this.shrinkToFit = shrinkToFit;
        return this;
    }

    public StyleModel build() {
        return new StyleModel(this);
    }

}
